<?php
if (!defined('ZZQSS')){
	die("Access Denied");
}
/*******************
*feedback 类，处理留言相关操作
*add()
*repay()
*del()
*clear()
*/
class FeedBack{
	var $db;
	var $table;
	
	function __construct()
	{
		global $db,$tablepre;
		$this->db=$db;
		$this->table=$tablepre."feedback";
	}
	function FeedBack(){
		$this->__construct();
	}
	
	/**
	 * 添加意见反馈
	 *
	 * @param unknown_type $name
	 * @param unknown_type $tel
	 * @param unknown_type $msg
	 * @param 2反馈1提供团购 $tid
	 * @return unknown
	 */
	function add($name,$tel,$msg,$tid=1)
	{
		global $timestamp;
		if(!empty($name)){
			$sql="insert into {$this->table}(name,tel,msg,addtime,tid) VALUES('$name','$tel','$msg',$timestamp,$tid)";
			$this->db->query($sql);
			return "OK";
		}else return "缺少参数";
	}
	function del($fid)
	{
		if(is_numeric($fid))
		{	
			$this->db->query("delete from {$this->table} where fid=$fid limit 1");	
			return true;
		}else{
			return false;
		}
	}
	function edit($fid,$name,$msg)
	{	
		if(is_numeric($fid)&&!empty($name)){
			$sql="UPDATE {$this->table} SET name='{$name}',msg='{$msg}' where fid='{$fid}'";
			$this->db->query($sql);	
			return true;
		}return false;
	}
	function state($fid,$state=""){
		
		if($state===""){
			return $this->db->result_first("Select state From `$this->table` WHERE fid='{$fid}'");
		}elseif (($state==0 || $state==1)&&is_numeric($fid)){
			$this->db->query("update `$this->table` SET state = {$state} WHERE fid={$fid}");
			return true;
		}else return false;	
	}
	
	function getdata($limit="",$where="",$orderby=""){
		$tempdata=array();
		if(!empty($limit))$limit=" limit $limit ";
		if(!empty($where))$where=" where $where ";
		if(!empty($orderby))$orderby=" order by $orderby ";else $orderby=" order by fid desc";
		$sql="select * from {$this->table}{$where}{$orderby}{$limit}";
		$query =$this->db->query($sql);
		while($value = $this->db->fetch_array($query)) {
			$tempdata[]=$value;
		}
		return $tempdata;
	
	}
	function getcount($where=""){
	if(!empty($where))$where=" where $where";
	$count= $this->db->result_first("Select count(*) From `$this->table` $where");
	return $count;
	
	}

	function clear()
	{
		$this->db->query("delete from {$this->table} where 1");	
		return true;		
	}
	
}

?>